#########################################################################
##
## This file is part of the SAMRAI distribution.  For full copyright 
## information, see COPYRIGHT and LICENSE. 
##
## Copyright:     (c) 1997-2019 Lawrence Livermore National Security, LLC
## Description:   makefile for testing patch data operations 
##
#########################################################################

SAMRAI        = @top_srcdir@
SRCDIR        = @srcdir@
SUBDIR        = source/test/dataops
VPATH         = @srcdir@
TESTTOOLS     = ../testtools
OBJECT        = ../../..
REPORT        = $(OBJECT)/report.xml

# These need to be built up separately to avoid race conditions when
# writing to the report file.
REPORT1       = $(OBJECT)/report1
REPORT2       = $(OBJECT)/report2

default: check	

include $(OBJECT)/config/Makefile.config

CPPFLAGS_EXTRA	= -DDISPLAY -DTESTING=1

ifneq (,$(findstring libdcomplex, $(SAMRAI_LIBRARY_TARGETS)))
  NUM_TESTS = 24
else
  NUM_TESTS = 14
endif

TEST_NPROCS = @TEST_NPROCS@
QUOTE = \"


SampleIndexData.o:	$(SAMRAI)/source/test/dataops/SampleIndexData.C
	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(SAMRAI)/source/test/dataops/SampleIndexData.C -o $@

indx_dataops:		indx_dataops.o  SampleIndexData.o $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) indx_dataops.o SampleIndexData.o $(LIBSAMRAI2D) $(LIBSAMRAI) $(LDLIBS) -o $@

cell_patchtest:		cell_patchtest.o  $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) cell_patchtest.o $(LIBSAMRAI2D) $(LIBSAMRAI) $(LDLIBS) -o $@

cell_hiertest:		cell_hiertest.o  $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) cell_hiertest.o $(LIBSAMRAI2D) $(LIBSAMRAI) $(LDLIBS) -o $@

cell_hiertest3d:	cell_hiertest.o  $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) cell_hiertest.o $(LIBSAMRAI3D) $(LIBSAMRAI) $(LDLIBS) -o $@

edge_hiertest:		edge_hiertest.o  $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) edge_hiertest.o $(LIBSAMRAI2D) $(LIBSAMRAI) $(LDLIBS) -o $@

face_hiertest:		face_hiertest.o  $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) face_hiertest.o $(LIBSAMRAI2D) $(LIBSAMRAI) $(LDLIBS) -o $@

side_hiertest:		side_hiertest.o  $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) side_hiertest.o $(LIBSAMRAI2D) $(LIBSAMRAI) $(LDLIBS) -o $@

node_hiertest:		node_hiertest.o  $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) node_hiertest.o $(LIBSAMRAI2D) $(LIBSAMRAI) $(LDLIBS) -o $@

cell_cplxtest:		cell_cplxtest.o  $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) cell_cplxtest.o $(LIBSAMRAI2D) $(LIBSAMRAI) $(LDLIBS) -o $@

edge_cplxtest:		edge_cplxtest.o  $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) edge_cplxtest.o $(LIBSAMRAI2D) $(LIBSAMRAI) $(LDLIBS) -o $@

node_cplxtest:		node_cplxtest.o  $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) node_cplxtest.o $(LIBSAMRAI2D) $(LIBSAMRAI) $(LDLIBS) -o $@

face_cplxtest:		face_cplxtest.o  $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) face_cplxtest.o $(LIBSAMRAI2D) $(LIBSAMRAI) $(LDLIBS) -o $@

side_cplxtest:		side_cplxtest.o  $(LIBSAMRAIDEPEND) 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) side_cplxtest.o $(LIBSAMRAI2D) $(LIBSAMRAI) $(LDLIBS) -o $@


TARGETS2D=	cell_patchtest \
	        cell_hiertest \
		face_hiertest \
		node_hiertest \
		side_hiertest \
		edge_hiertest \
		indx_dataops

ifneq (,$(findstring complex, $(SAMRAI_LIBRARY_TARGETS)))
TARGETS2D+=	cell_cplxtest \
		face_cplxtest \
		node_cplxtest \
		side_cplxtest \
		edge_cplxtest
endif


checkcompile:   $(TARGETS2D) cell_hiertest

check:
	$(MAKE) check2d
	cat $(REPORT1) $(REPORT2) >> $(REPORT)
	$(RM) $(REPORT1)
	$(RM) $(REPORT2)


check2d:	$(SAMRAI_LIBRARY_TARGETS)

check3d:	$(SAMRAI_LIBRARY_TARGETS)

libbool:

libchar:

libfloat:

# Note that tmp file names need to be distinct between targets
# libdcomplex and libdefault to prevent race conditions using parallel
# make.

libdcomplex:	cell_cplxtest \
		face_cplxtest \
		node_cplxtest \
		side_cplxtest \
		edge_cplxtest
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)cell_cplxtest 2d $$p procs$(QUOTE)>" >> $(REPORT1); \
	  $(OBJECT)/config/serpa-run $$p ./cell_cplxtest 2 | $(TEE) foo-cplx; \
	  if ! grep "PASSED" foo-cplx >& /dev/null ; then echo "      <failure/>" >> $(REPORT1); fi; \
	  echo "    </testcase>" >> $(REPORT1); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)cell_cplxtest 3d $$p procs$(QUOTE)>" >> $(REPORT1); \
	  $(OBJECT)/config/serpa-run $$p ./cell_cplxtest 3 | $(TEE) foo-cplx; \
	  if ! grep "PASSED" foo-cplx >& /dev/null ; then echo "      <failure/>" >> $(REPORT1); fi; \
	  echo "    </testcase>" >> $(REPORT1); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)face_cplxtest 2d $$p procs$(QUOTE)>" >> $(REPORT1); \
	  $(OBJECT)/config/serpa-run $$p ./face_cplxtest 2 | $(TEE) foo-cplx; \
	  if ! grep "PASSED" foo-cplx >& /dev/null ; then echo "      <failure/>" >> $(REPORT1); fi; \
	  echo "    </testcase>" >> $(REPORT1); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)face_cplxtest 3d $$p procs$(QUOTE)>" >> $(REPORT1); \
	  $(OBJECT)/config/serpa-run $$p ./face_cplxtest 3 | $(TEE) foo-cplx; \
	  if ! grep "PASSED" foo-cplx >& /dev/null ; then echo "      <failure/>" >> $(REPORT1); fi; \
	  echo "    </testcase>" >> $(REPORT1); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)node_cplxtest 2d $$p procs$(QUOTE)>" >> $(REPORT1); \
	  $(OBJECT)/config/serpa-run $$p ./node_cplxtest 2 | $(TEE) foo-cplx; \
	  if ! grep "PASSED" foo-cplx >& /dev/null ; then echo "      <failure/>" >> $(REPORT1); fi; \
	  echo "    </testcase>" >> $(REPORT1); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)node_cplxtest 3d $$p procs$(QUOTE)>" >> $(REPORT1); \
	  $(OBJECT)/config/serpa-run $$p ./node_cplxtest 3 | $(TEE) foo-cplx; \
	  if ! grep "PASSED" foo-cplx >& /dev/null ; then echo "      <failure/>" >> $(REPORT1); fi; \
	  echo "    </testcase>" >> $(REPORT1); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)edge_cplxtest 2d $$p procs$(QUOTE)>" >> $(REPORT1); \
	  $(OBJECT)/config/serpa-run $$p ./edge_cplxtest 2 | $(TEE) foo-cplx; \
	  if ! grep "PASSED" foo-cplx >& /dev/null ; then echo "      <failure/>" >> $(REPORT1); fi; \
	  echo "    </testcase>" >> $(REPORT1); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)edge_cplxtest 3d $$p procs$(QUOTE)>" >> $(REPORT1); \
	  $(OBJECT)/config/serpa-run $$p ./edge_cplxtest 3 | $(TEE) foo-cplx; \
	  if ! grep "PASSED" foo-cplx >& /dev/null ; then echo "      <failure/>" >> $(REPORT1); fi; \
	  echo "    </testcase>" >> $(REPORT1); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)side_cplxtest 2d $$p procs$(QUOTE)>" >> $(REPORT1); \
	  $(OBJECT)/config/serpa-run $$p ./side_cplxtest 2 | $(TEE) foo-cplx; \
	  if ! grep "PASSED" foo-cplx >& /dev/null ; then echo "      <failure/>" >> $(REPORT1); fi; \
	  echo "    </testcase>" >> $(REPORT1); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)side_cplxtest 3d $$p procs$(QUOTE)>" >> $(REPORT1); \
	  $(OBJECT)/config/serpa-run $$p ./side_cplxtest 3 | $(TEE) foo-cplx; \
	  if ! grep "PASSED" foo-cplx >& /dev/null ; then echo "      <failure/>" >> $(REPORT1); fi; \
	  echo "    </testcase>" >> $(REPORT1); \
	done; \
	$(RM) foo-cplx


libdefault:	cell_patchtest \
		cell_hiertest \
		face_hiertest \
		node_hiertest \
		side_hiertest \
		edge_hiertest \
		indx_dataops
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)indx_dataops 2d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./indx_dataops 2 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)indx_dataops 3d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./indx_dataops 3 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)cell_hiertest 2d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./cell_hiertest 2 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)cell_hiertest 3d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./cell_hiertest 3 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)cell_patchtest 2d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./cell_patchtest 2 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)cell_patchtest 3d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./cell_patchtest 3 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)face_hiertest 2d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./face_hiertest 2 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)face_hiertest 3d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./face_hiertest 3 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)node_hiertest 2d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./node_hiertest 2 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)node_hiertest 3d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./node_hiertest 3 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)edge_hiertest 2d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./edge_hiertest 2 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)edge_hiertest 3d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./edge_hiertest 3 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)side_hiertest 2d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./side_hiertest 2 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done
	@for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	  echo "    <testcase classname=\"dataops\" name=$(QUOTE)side_hiertest 3d $$p procs$(QUOTE)>" >> $(REPORT2); \
	  $(OBJECT)/config/serpa-run $$p ./side_hiertest 3 | $(TEE) foo; \
	  if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT2); fi; \
	  echo "    </testcase>" >> $(REPORT2); \
	done; \
	$(RM) foo

checktest:
	$(RM) makecheck.logfile
	$(MAKE) check 2>&1 | $(TEE) makecheck.logfile
	$(TESTTOOLS)/testcount.sh $(TEST_NPROCS) $(NUM_TESTS) 0 makecheck.logfile
	$(RM) makecheck.logfile

examples:

perf:

everything:
	$(MAKE) checkcompile || exit 1
	$(MAKE) checktest
	$(MAKE) examples
	$(MAKE) perf

checkclean:
	$(CLEAN_COMMON_CHECK_FILES)

clean:	checkclean
	$(CLEAN_COMMON_TEST_FILES)
	$(RM) *_hiertest *_cplxtest *_patchtest *_dataops


include $(SRCDIR)/Makefile.depend
